package Demo;


import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread( () -> {
           synchronized (locker1) {
               System.out.println("t1等待前");
               try {
                   locker1.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("t1等待后");
           }
        });

        Thread t2 = new Thread( () -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入任意值,用来唤醒t1线程");
            scanner.next();
           synchronized (locker1) {
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               locker1.notify();
           }
        });

        t1.start();
        t2.start();
    }
}
